import { h } from "vue";
import { VxeUI } from "vxe-pc-ui";
import VxeAreaSelect from "@/components/Vxe/VxeAreaSelect.vue";
import VxeImageUpload from "@/components/Vxe/VxeImageUpload.vue";
import VxeTable from "vxe-table";

// 注册所有图标
export function setupVxe() {
  VxeUI.renderer.add("VxeAreaSelect", {
    // 项显示模板
    renderItemContent(renderOpts, params) {
      return h(VxeAreaSelect, {
        renderOpts,
        params,
      });
    },
  });
  VxeUI.renderer.add("VxeTips", {
    // 项显示模板
    renderItemContent(renderOpts, params) {
      return renderOpts.props?.content ?? "";
    },
  });
  VxeUI.renderer.add("VxeImageUpload", {
    // 项显示模板
    renderItemContent(renderOpts, params) {
      return h(VxeImageUpload, {
        renderOpts,
        params,
      });
    },
  });

  VxeTable.setConfig({
    emptyCell: "-",
    grid: {
      proxyConfig: {
        props: {
          result: "rows", // 配置响应结果列表字段
          total: "total", // 配置响应结果总页数字段
        },
      },
    },
  });

  VxeUI.formats.add("doubleProp", {
    cellFormatMethod({ cellValue, row }, extraProp = null) {
      if (extraProp) {
        return [cellValue, row?.[extraProp]].filter((t) => t).join("<br/>");
      }
      return cellValue;
    },
  });
}
